package com.chinalwb.are.demo.slice;

import com.chinalwb.are.demo.ARE_ShowTextAbility;
import com.chinalwb.are.demo.DemoUtil;
import com.chinalwb.are.demo.ResourceTable;
import com.chinalwb.are.utils.FindUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.TextField;
import ohos.agp.window.service.WindowManager;

/**
 * ARE_MinHideSlice
 *
 * @since 2021/06/22
 */
public class ARE_MinHideSlice extends AbilitySlice {
    @Override
    protected void onStart(Intent intent) {
        DemoUtil.initStatus(getAbility());
        getWindow().setInputPanelDisplayType(WindowManager.LayoutConfig.INPUT_ADJUST_PAN);
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_min_hide);
        Image image = FindUtils.findImageById(getAbility(), ResourceTable.Id_icSend);
        Text tvContent = FindUtils.findTextById(getAbility(), ResourceTable.Id_tvContent);
        TextField textField = (TextField) findComponentById(ResourceTable.Id_cursor_text);
        Text showText = FindUtils.findTextById(getAbility(), ResourceTable.Id_showText);
        Text save = FindUtils.findTextById(getAbility(), ResourceTable.Id_save);
        image.setClickedListener(component -> {
            tvContent.setText(textField.getText());
            textField.setText("");
        });
        showText.setClickedListener(component -> {
            Intent intents = new Intent();
            Operation operation = new Intent.OperationBuilder()
                    .withBundleName("com.chinalwb.are.demo")
                    .withAbilityName(ARE_ShowTextAbility.class.getCanonicalName())
                    .build();
            intents.setParam("content", tvContent.getText());
            intents.setParam(ARE_ShowTextSlice.DEFAULT, "defaults");
            intents.setOperation(operation);
            startAbility(intents);
        });
        save.setClickedListener(component -> DemoUtil.saveHtml(getAbility(), tvContent.getText()));
    }
}
